package thread.chapter01;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 线程测试chapter01
 * @date 2023/12/8 10:47:02
 */
public class ThreadTest {

    // ）创建ThreadLocal 交量
    static ThreadLocal<String> localVariable = new ThreadLocal<>();
    static void print(String str) {
        System.out.println(str + ":" +localVariable.get());
    }
    // 1.11.1
    public static void main(String[] args) {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                // 设置线程One 中本地交localVariable 的位
                localVariable.set("threadOne local variable");
                print("threadOne");
                //本地变量值
                System.out.println("threadOne remove after : "+ localVariable.get());

            }
        });

        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                // 设置线程One 中本地交localVariable 的位
                localVariable.set("threadTwo local variable");
                print("threadOne");
                //本地变量值
                System.out.println("threadTwo remove after : "+ localVariable.get());

            }
        });

        threadOne.start();
        threadTwo.start();
    }
}
